#include <iostream>
#include <zlib/eventsystem/P_Queue.h>

using namespace std;

int main()
{
	ink_hrtime cur_time = ink_time_nsecond();
	PriorityQueue q;
	Event e1;
	e1.init(NULL, ink_hrtime_from_msecond(6), 0);
	q.enqueue(&e1, cur_time);
	Event e2;
	e2.init(NULL, 15, 0);
	q.enqueue(&e2, cur_time);
	Event e3;
	e3.init(NULL, 30, 0);
	q.enqueue(&e3, cur_time);
	
	Event e4;
	e4.init(NULL, 10, 0);
	q.enqueue(&e4, cur_time);

	q.check_ready(cur_time);

	cout << &e1 << " " << &e2 << " " << &e3 << " " << &e4 << endl;
	
	Event *e;
	while((e = q.dequeue()))
	{
		cout << e->timeout_at << " ";
	}
	cout << endl;

	cout << "current event timeout:" << cur_time << endl;
	cout << "near event timeout:" << q.get_near_exec_time() <<  endl;
	cout << "interval:" << q.get_near_exec_time() - cur_time << endl;

	return 0;
}
